package org.cqipc.edu.controller;

import org.cqipc.edu.common.Pages;
import org.cqipc.edu.service.GoodsService;
import org.cqipc.edu.utils.CommonUtils;
import org.cqipc.edu.vo.GoodsResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Description: 宠物控制器
 * @ClassNmae: GoodsController
 * @Author: HeYue
 * @DateTime: 2020-11-01 14:20
 **/
@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("/uploadFile")
    public Object upload(MultipartFile goodsImage, GoodsResultVO goodsResultVO, HttpSession session) throws IOException {
        return goodsService.addGoodsInfo(goodsImage, goodsResultVO, session);
    }

    @GetMapping("/getGoodsList")
    public Object getGoodsList(Integer limit, Integer page, HttpSession session) {
        return goodsService.getGoodsPage(new Pages(page, limit), session);
    }


    @PutMapping("/batchGrounding")
    public Object batchGrounding(@RequestParam("ids") String ids) {
        return goodsService.batchGrounding(CommonUtils.StringToIntegerlIST(ids, ","));
    }

    @PutMapping("/batchUndercarriage")
    public Object batchUndercarriage(@RequestParam("ids") String ids) {
        return goodsService.batchUndercarriage(CommonUtils.StringToIntegerlIST(ids, ","));
    }

    @DeleteMapping("/batchDelete")
    public Object batchDelete(@RequestParam("ids") String ids) {
        return goodsService.batchDelete(CommonUtils.StringToIntegerlIST(ids, ","));
    }

    @GetMapping("/getGoodsById/{id}")
    public Object getGoodsById(@PathVariable("id") Integer id) {
        return goodsService.getGoodsById(id);
    }

    @GetMapping("getPageCount")
    public Object getPageCount(HttpSession session) {
        return goodsService.getPageCount(session);
    }

    @GetMapping("/getGoodsShow")
    public Object getGoodsShow(Integer page, Integer limit, HttpSession session) {
        return goodsService.getGoodsPageShow(new Pages(page, limit), session);
    }

    @GetMapping("/getPageCountToiIndex")
    public Integer getPageCountToiIndex() {
        return goodsService.getPageCountToiIndex();
    }

    @GetMapping("/getGoodsShowToIndex")
    public Object getGoodsShowToIndex(Integer page, Integer limit, HttpSession session) {
        return goodsService.getGoodsShowToIndex(new Pages(page, limit), session);
    }

    @GetMapping("/getGoodsShowById")
    public Object getGoodsShowById(Integer id) {
        return goodsService.getGoodsShowById(id);
    }

    @GetMapping("/seacherInfoCount")
    public Integer getGoodsShowById(String text) {
        return goodsService.seacherInfoCount(text);
    }

    @GetMapping("/seacherInfo")
    public Object seacherInfo(String text, Integer page, Integer limit, HttpSession session) {
        return goodsService.seacherInfo(text, new Pages(page, limit), session);
    }


}
